/**
 * Created by Galois on 2017/7/4.
 */
$(function(){
    console.log("加油");
    var mainLoading = false;
    getContent();

    function getData(result) {
        if(result.status==200){
            return result.data;
        }else{
            alert(result.messages||"获取信息错误");
            return null;
        }
    }

    function getContent(result){
        if (mainLoading) return;

        $.get("Admin/index.action",function (result, err) {
            var items = getData(result);
            appendContent(items);
        })

        mainLoading = true;
    }

    /*把获取到的列表信息填充入#List中*/
    function appendContent(items){
        console.log("appendContent");
        var contentMain;
        var listContentMain=[];
        items.forEach(function(itemMain){
            listContentMain.push('<div class="main">');
            listContentMain.push('    <div class="main_content">');
            listContentMain.push('        <div class="news">');
            listContentMain.push('            <div class="news_title">');
            listContentMain.push('               <h>'+ itemMain.title[0] +'</h>');
            listContentMain.push('                <a href="'+ itemMain.moreHref[0] +'">更多<img src="images/more_too.jpg"></a>');
            listContentMain.push('            </div>');
            listContentMain.push('            <div class="news_content">');
            listContentMain.push('                <div class="news_content">');
            listContentMain.push('                    <a href="'+ itemMain.imgHref[0] +'"><img src="'+ itemMain.img[0] +'" /></a>');
            listContentMain.push('               </div><!--news_content结束-->');
            listContentMain.push('            </div><!--news_content结束-->');
            listContentMain.push('        </div><!--news结束-->');
            listContentMain.push('        <div class="news2">');
            listContentMain.push('            <div class="news_title">');
            listContentMain.push('                <h>'+ itemMain.title[1] +'</h>');
            listContentMain.push('                <a href="'+ itemMain.moreHref[1] +'">更多<img src="images/more_too.jpg"></a>');
            listContentMain.push('            </div><!--news_title结束-->');
            listContentMain.push('            <div class="news_content">');
            listContentMain.push('                <div class="news_content">');
            listContentMain.push('                   <a href="'+ itemMain.imgHref[1] +'" target="_blank" ><img src="'+ itemMain.img[1] +'" /></a>');
            listContentMain.push('                </div><!--news_content结束-->');
            listContentMain.push('            </div><!--news_content结束-->');
            listContentMain.push('        </div><!--news2结束-->');
            listContentMain.push('        <div class="news3">');
            listContentMain.push('            <div class="news_title">');
            listContentMain.push('                <h>'+ itemMain.title[2] +'</h>');
            listContentMain.push('                <a href="'+ itemMain.moreHref[2] +'">更多<img src="images/more_too.jpg" /></a>');
            listContentMain.push('            </div><!--news_title结束-->');
            listContentMain.push('            <div class="news_content">');
            listContentMain.push('                <div class="news_content">');
            listContentMain.push('                    <a href="'+ itemMain.imgHref[2] +'" target="_blank"><img src="'+ itemMain.img[2] +'" /></a>');
            listContentMain.push('                    </div><!--news_content结束-->');
            listContentMain.push('            </div><!--news_title3结束-->');
            listContentMain.push('        </div><!--news3结束-->');
            listContentMain.push('    </div><!--main_content结束-->');
            listContentMain.push('</div><!--main结束-->');
        });
        contentMain = listContentMain.join("");                 //  连成一句话
        $("#contentMain").append(contentMain);
        mainLoading = false;     //加载完毕
    }
});